package com.mscsoft.brainpower.server.dao;

import com.mscsoft.brainpower.server.domain.GameScore;
import com.mscsoft.brainpower.server.domain.ScoreRank;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.*;

@Mapper
public interface GameDao {
        @Select("select * from score where uid=#{uid} and msid=#{msid}")
        GameScore queryGameScoreByUidAndMsid(@Param("uid") int uid, @Param("msid") int msid);

        @Insert("INSERT INTO score (uid,msid,score,combo,ap,fc) VALUES(#{uid},#{msid},#{score},#{combo},#{ap},#{fc})")
        void insertGameScore(@Param("uid") int uid, @Param("msid") int msid, @Param("score") int score,
                        @Param("combo") int combo, @Param("ap") boolean ap, @Param("fc") boolean fc);

        @Update("UPDATE score SET score=#{score},combo=#{combo},ap=#{ap},fc=#{fc} WHERE uid=#{uid} and msid=#{msid}")
        void updateGameScore(@Param("uid") int uid, @Param("msid") int msid, @Param("score") int score,
                        @Param("combo") int combo, @Param("ap") boolean ap, @Param("fc") boolean fc);

        @Select("SELECT user.name,score FROM score,user WHERE msid=#{msid} AND score.uid=user.uid ORDER BY score DESC, time ASC LIMIT 0,5")
        ScoreRank[] queryScoreRankByMsid(@Param("msid") int msid);
}
